<?php

namespace app\dao\exam;

use app\dao\BaseDao;
use app\model\exam\ExamQuestion;

class ExamQuestionDao extends BaseDao
{

    public function index(array $where)
    {
        return $this->getModel()->withSearch(['title', 'type', 'pattern', 'paper_name'], ['title' => $where['title'],
            'type' => $where['type'], 'pattern' => $where['pattern'], 'paper_name' => $where['paper_name']])
            ->where('website_id', $where['website_id'])->order('id', 'desc')->paginate($where['pageSize']);
    }

    public function updateDao(array $where)
    {
        unset($where['website_id']);
        return $this->search()->update($where);
    }

    public function create(array $where)
    {
        unset($where['id']);
        return $this->search()->create($where);
    }

    public function deleteDao(array $where)
    {
        return $this->getModel()->whereIn('id', $where['id'])->update(['delete_time' => date('Y-m-d H:i:s', time())]);
    }

    protected function setModel(): string
    {
        return ExamQuestion::class;
    }
}